#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

char primitive[11][11];
char trans[11][11];
char ultimate[11][11];
int main()
{
	int n;
	char ch;
	scanf("%d\n", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			scanf("%c", &primitive[i][j]);
		}
		ch=getchar();
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			scanf("%c", &ultimate[i][j]);
		}
		ch = getchar();
	}
	for(int i=1;i<=n;i++)
		for (int j = 1; j <= n; j++) {
			if (primitive[i][j] != ultimate[j][n - i + 1]) { goto end1; }
		}
	printf("%d", 1);
	return 0;
end1:;
	for(int i=1;i<=n;i++)
		for (int j = 1; j <= n; j++) {
			if (primitive[i][j] != ultimate[n - i + 1][n - j + 1]) { goto end2; }
		}
	printf("%d", 2);
	return 0;
end2:;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			if (primitive[i][j] != ultimate[n-j+1][i]) { goto end3; }
		}
	printf("%d", 3);
	return 0;
end3:;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			if (primitive[i][j] != ultimate[i][n-j+1]) { goto end4; }
		}
	printf("%d", 4);
	return 0;
end4:;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			trans[i][j] = primitive[i][n - j + 1];
		}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			if (trans[i][j] != ultimate[j][n - i + 1]) { goto out1; }
		}
	goto end5;
out1:;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			if (trans[i][j] != ultimate[n - i + 1][n - j + 1]) { goto out2; }
		}
	goto end5;
out2:;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			if (trans[i][j] != ultimate[n - j + 1][i]) { goto out3; }
		}
end5:;
	printf("%d", 5);
	return 0;
out3:;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			if (primitive[i][j] != ultimate[i][j]) { goto end6; }
		}
	printf("%d", 6);
	return 0;
end6:;
	printf("%d", 7);
	return 0;
}